--
-- Author: Xing Wenju
-- Date: 2014-04-04 12:22:27
--

list_table = nil

do 
    function _list_table(tb, level)
        for k, v in pairs(tb) do 
            -- indentify the index type
            local fc, tc
            if type(k) == "number" then
                fc, tc = "[", "]"
            else
                fc, tc = "\"", "\""
            end

            if type(v) == "table" then 
                -- if it is a table, recursive call _list_table.
                print(level .. fc .. k .. tc .. " = {")
                _list_table(v, level .. "    ")
                print(level .. "}")
            else
                print(level .. fc .. k .. tc .. " = <" .. type(v) .. "> " .. tostring(v))
            end
        end
    end

    list_table = function(tb) 
        if type(tb) ~= "table" then
            error("Sorry, it 's not table, it is " .. type(tb) .. '.')
        end

        print(tostring(tb) .. " = {")
        _list_table(tb, "    ")
        print("}")
    end
end


-- for test
test_table = {
    12, 22.5, true, 
    infor = {
        name = "Jack", age = 26,
        lifeexp = {
            ["1986"] = "Both",
            ["2013"] = "Work in Tencet",
            ["2015"] = "Get married"
        }, 
        wife = "Lucy"
    },
    "Hello test",
    ["2"] = 13
}

list_table(test_table)
a = 12
list_table(a)
